package com.augurit.wf.common.tag.input;

import java.io.Writer;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.augurit.wf.common.tag.base.WfPageElemWithPrivImpl;
import com.opensymphony.xwork2.util.ValueStack;
import de.odysseus.el.tree.Tree;

public class WfInput extends  WfPageElemWithPrivImpl{
	
	private String name;
	private String type;
	private String value;
	private String readOnly;
	private String cssClass;
	private String disabled;	//是否锁定
	private String hidden;		//是否隐藏
	
	
	private String debug; //调试，显示当前权限
	private String onblur;
	private String onfocus;
	private String onclick;
	private String onmousemove;
	private String onmouseover;
	private String width;
	private String align;
	private String style;
	private String size;
	private String height;
	
	
	public WfInput(ValueStack arg0) {
		super(arg0);
	}
	
	@Override
	public boolean start(Writer arg0) {
		boolean result = super.start(arg0);
		try {
			 StringBuilder str = new StringBuilder();
			 //如果没有被权限隐藏
			 if(!this.isHiddenByPriv() ){
				

					
					str.append("<input ");
					if (name != null) {
						str.append(" name=\"" + name + "\"");
					}
					if( type != null){
						str.append(" type=\"" + type + "\"");
					}
					if (this.getId() != null) {
						str.append("id=\"" + this.getId() + "\"");
					}
					
					
					//如果没有被权限锁定
					if(type.equals("button")){
						if(!this.isDisabledByPriv()){
							if (disabled != null) {
								str.append(" disabled=\"" + disabled + "\"");
							}
						}
						else{
							str.append(" disabled=\"true\"");
							this.cssClass = null;
						}
					}
					else{
						if(!this.isDisabledByPriv()){
							if (readOnly != null) {
								str.append(" readonly=\"" + readOnly + "\"");
							}
						}
						else{
							str.append(" readonly");
						}
					}
					
					if( cssClass != null){
						str.append(" class=\"" + cssClass + "\"");
					}
					if (value != null) {
						str.append(" value=\"" + value + "\"");
					}
					if (height != null) {
						str.append(" height=\"" + height + "\"");
					}
					if (onblur != null) {
						str.append(" onblur=\"" + onblur + "\"");
					}
					if (width != null) {
						str.append(" width=\"" + width + "\"");
					}
					if (align != null) {
						str.append(" align=\"" + align + "\"");
					}
					if (style != null) {
						str.append(" style=\"" + style + "\"");
					}
					if (size != null) {
						str.append(" size=\"" + size + "\"");
					}
					
					if(onfocus != null){
						str.append(" onfocus=\"" + onfocus + "\"");
					}
					
					if(onclick != null){
						str.append(" onclick=\"" + onclick + "\"");
					}
					if(onmouseover != null){
						str.append(" onmouseover=\"" + onmouseover + "\"");
					}
					if(onmousemove != null){
						str.append(" onmousemove=\"" + onmousemove + "\"");
					}
					str.append("/>");
				
				
			 }
				
				
			arg0.write(str.toString());
		} catch (Exception e) {
			Logger.getLogger(Tree.class.getName()).log(Level.WARN, null, e);
		}
		return result;
	}
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getReadOnly() {
		return readOnly;
	}

	public void setReadOnly(String readOnly) {
		this.readOnly = readOnly;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getHidden() {
		return hidden;
	}

	public void setHidden(String hidden) {
		this.hidden = hidden;
	}

	public String getDebug() {
		return debug;
	}

	public void setDebug(String debug) {
		this.debug = debug;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getOnblur() {
		return onblur;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}
	
	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getOnfocus() {
		return onfocus;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getOnmousemove() {
		return onmousemove;
	}

	public void setOnmousemove(String onmousemove) {
		this.onmousemove = onmousemove;
	}

	public String getOnmouseover() {
		return onmouseover;
	}

	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}
	
	
}
